// pages/list/list.js
const http = require("../../utils/http");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    endType: false
  },
  customData:{
    pageNow: 1,keyWord: ""
  },
getList(keyword){
  http.request("/requirement/request/getMatchedProducts", { "keyWord": keyword, "curPagePath": "/wx/customer/classic/search.html?pageid=mAK3Big1KB4ygfZFgswR", "product_type": 1, "pageNow": this.customData.pageNow, "pageSize": 10 }, "post").then(res => {
    console.log(res);
    this.setData({
      list: res.data.matchedProducts
    })
  })
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.customData.keyWord=options.searchtext;
    // this.setData({
    //   keyWord: options.searchtext
    // })
this.getList(options.searchtext);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
this.getList(this.data.keyWord);
wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (!this.data.endType) {
      this.customData.pageNow++;
      http.request("/requirement/request/getMatchedProducts", { "keyWord": this.customData.keyWord, "curPagePath": "/wx/customer/classic/search.html?pageid=mAK3Big1KB4ygfZFgswR", "product_type": 1, "pageNow": this.customData.pageNow, "pageSize": 10 }, "post").then(res => {
        console.log(res);
        if(res.data.matchedProducts.length===0){
          this.setData({
            endType:true
          })
        }
        this.setData({
          list: this.data.list.concat(res.data.matchedProducts)
        })
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})